package com.example.pattern.draw.shape

import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.graphics.PointF
import android.graphics.RectF
import android.graphics.Region


class CurveShape:Shape() {
    private val mPath = Path()
    override var startPoint:PointF = PointF(0f,0f)
        get() = super.startPoint
        set(value) {
            field = value
            mPath.moveTo(value.x,value.y)
        }

    override fun containsPoint(x: Float, y: Float): Boolean {
        val bounds = RectF()
        mPath.computeBounds(bounds, true)
        val region = Region()
        region.setPath(mPath, Region((bounds.left).toInt(), (bounds.top).toInt(), (bounds.right).toInt(), (bounds.bottom).toInt()))

        return region.contains(x.toInt(), y.toInt())
    }

    override fun drawShape(canvas: Canvas) {
        mPath.lineTo(endPoint.x,endPoint.y)
        mPaint.strokeCap =Paint().strokeCap
        mPaint.style = Paint.Style.STROKE
        canvas.drawPath(mPath,mPaint)
    }
}